<?php

namespace App\Http\Controllers;

use App\Models\Legend;
use Illuminate\Http\Request;

class LegendController extends Controller
{
    function list() {
        $pn = request()->input('pn', config('api.page_num'));
        $list = Legend::where('show', 1)
            ->select('id', 'name', 'head_img', 'main_honor', 'score')
            ->orderBy('score', 'desc')
            ->paginate($pn);
        return response()->json(['recode' => 1,
            'data' => ['last_page' => $list->lastPage()
                , 'page' => $list->currentPage()
                , 'list' => $list->items()]]);

    }

    public function info()
    {
        $id = request()->input('id', 0);

        $info = Legend::find($id);
        if ($info) {
            return response()->json(
                [
                    'recode' => 1,
                    'info' => $info,
                ]
            );
        }
        return response()->json(
            [
                'recode' => 0,
                'msg' => '未找到详情',
            ]
        );

    }
}
